package com.sz.security.core;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.handler.SaAnnotationHandlerInterface;
import cn.dev33.satoken.stp.StpLogic;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;

/**
 * @author sz
 * @since 2025/11/13 14:00
 * @version 1.0
 */
public class MySaCheckLoginHandler implements SaAnnotationHandlerInterface<SaCheckLogin> {

    @Override
    public Class<SaCheckLogin> getHandlerAnnotationClass() {
        return SaCheckLogin.class;
    }

    @Override
    public void check(Annotation at, AnnotatedElement element) {
        SaAnnotationHandlerInterface.super.check(at, element);
    }

    @Override
    public void checkMethod(SaCheckLogin at, AnnotatedElement element) {
        // Get the StpLogic for the specified login type
        StpLogic stpLogic = SaManager.getStpLogic(at.type());
        // Check if user is logged in for this login type
        stpLogic.checkLogin();
    }
}